package com.jh.concurrent.juc.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title ConditionAwait.java
 * @package com.jh.concurrent.juc
 * @description Condition的await方法
 * @date 2019-05-20 11:19
 */
public class ConditionAwait extends Thread{

    private Lock lock;

    private Condition condition;

    public ConditionAwait(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }

    @Override
    public void run() {
        System.out.println("begin -Condition await");
        try {
            lock.lock();
            condition.await();
            System.out.println("end -Condition await");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }
}
